<?php
// Session class takes care of login, logout and stores userid.

class Session {
	
	private $logged_in=false;
	public $user_id;

	
	function __construct() {
		session_start();
		$this->check_login();
                
	}
	
        // Checks if user is logged in or not
        public function is_logged_in() {
            return $this->logged_in;
        }
        
        // Saves a logged in users id in session
	public function login($user) {
        // database should find user based on username/password
            if($user){
                $this->user_id = $_SESSION['user_id'] = $user->user_id;
                $this->logged_in = true;
            }
        }
  
        // Logges out user, removes user_id from session
        public function logout() {
            unset($_SESSION['user_id']);
            unset($this->user_id);
            $this->logged_in = false;
        }

     
        // Checks if user are logged in or not
	private function check_login() {
            if(isset($_SESSION['user_id'])) {
                $this->user_id = $_SESSION['user_id'];
                $this->logged_in = true;
            } else {
                unset($this->user_id);
                $this->logged_in = false;
            }
  }
        
	
}

$session = new Session();


?>